##Smartag V3.2

##Overview:
This code is used for a proof of concept smart packaging sensor to validate storage conditions of medicines: SPaRAS. This code is being published alongside the paper: "A Customisable Environmental Sensor to Enable Prescription Medicine Reuse" in Nature Communications.
This code was developed by James Gerrans' throughout the duration of his PhD at the University of Reading.
Test code for the RTC driver, SHT4x driver, and flash communication protocol was originally developed by Simon Sherratt which was then adapted and incorporated into the SMARTAG V3.2 project by James Gerrans.

The purpose of this device is to monitor the storage conditions of medicines while in patient care. This can be done by activating SPaRAS and transferring a JSON file that contains information on assigned medicines and configurations to alter sensor function to tailor the device to the medicine's needs.
The environmental data will then be stored on the board for it to be read over NFC on return to the pharmacy and compared to a standardised criterium for the medicines using a companion app (not yet developed).

##System Requirements and Dependencies:
This code was developed in C and designed to run on the STmicroelectornics SMARTAG2 Evaluation Board(https://www.st.com/en/evaluation-tools/steval-smartag2.html  [accessed: 16/01/2026]) No other versions have been tested.
Additions made to the Board include:
(a)A Sensirion SHT4x humidity sensor (https://sensirion.com/products/catalog/SHT40-AD1F  [accessed: 16/01/2026]); (b)A Real-Time Clock (RTC) (https://www.st.com/en/clocks-and-timers/m41t80.html  [accessed: 16/01/2026]); and (c) A Crystall Oscillator(https://www.uxcell.com/pcs-3mmx8mm-32768hz-32768khz-cylinder-shaped-crystal-oscillators-silver-tone-p-694081.html  [accessed: 16/01/2026])
This will require the STM32CubeIDE 1.14.1 and a STLINK_V3MINIE to compile on the board.
Layout of hardware changes can be found in SPaRASHardware.png.
 
To change the functionality of the board while in use, a JSON file in the format included (JSONInput V3 WkTst1.json) will need to be transferred to the device over Near Field Communication (NFC) at an offset of 0x2C bytes.
To communicate with the board over NFC, the ST25 NFC Tap app is required (https://play.google.com/store/apps/details?id=com.st.st25nfc&hl=en_GB&pli=1 [accessed: 16/01/2026])
Environmental data can be read from the Board in binary format via NFC. 
To be human readable, This will need to be decoded into .txt and.csv files using the ReadSmartag2-VFlash C program.

##Terms of Use:
Data, modifications to FP-SNS-SMARTAG2 code and documentation: copyright 2026 James and Gerrans and University of Reading. This material is licensed under a Creative Commons Attribution 4.0 International Licence: https://creativecommons.org/licenses/by/4.0/.

FP-SNS-SMARTAG2 (STMicroelectronics example code for the SMARTAG2 Evaluation Board, which has been modified by the creators of this item): copyright 2022 STMicroelectronics. All Rights Reserved. This code is distributed under the terms of the STMicroelectronics software licence, which is reproduced in the folder STM32CubeFunctionPack_SMARTAG2_V1.1.0. 

##Acknowledgements:
This code is modified from the STmicroelectronics example code for the SMARTAG2 Evaluation Board (STM32CubeFunctionPack_SMARTAG2_V1.1.0)

Changes to the original ST code include:
The addition of an RTC driver to increase accuracy in keeping time and ability to change the period for which the board sleeps.
The ability to save environmental readings to Flash memory which can then be read using commands over NFC.
The addition of two virtual sensors to control the activation of the SHT4x temperature and humidity sensor
The ability to customise the device while in use with a JSON file transferred over NFC.
The ability to activate sensors at independant intervals.
The detection of a power outage/reset between Json file transfers.
The storage of information regarding assigned medicine.
Alteration of the structure in which information is stored on the NFC chip.
